﻿using MaximServices.Common;
using MaximServices.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;

namespace MaximPortal.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private TestServices _testServices;
        private MottoCheckServices _mottoCheckServices;

        public HomeController(TestServices testServices, MottoCheckServices mottoCheckServices)
        {
            _testServices = testServices;
            _mottoCheckServices = mottoCheckServices;
        }

        // GET api/home
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            var t = _testServices.SearchTests();

            var firstName = t != null && t.Count > 0 ? t.First().Name : "";
            var totalCount = t != null ? t.Count : 0;

            return new string[] { "value1", "value2", IdFactory.NextId.ToString(), totalCount.ToString() };
        }

        // GET api/home/5
        [HttpGet("{name}")]
        public ActionResult<string> Get(string name)
        {
            //_testServices.InsertTest();

            var result = _mottoCheckServices.GetBaikeUrl(name, null);

            return Json.ToJson(result);
        }

        // POST api/home
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/home/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/home/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
